package cn.ording.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;


/**
 * User entity. @author MyEclipse Persistence Tools
 */

public class User  implements java.io.Serializable,UserDetails {


    // Fields    

     private Integer uid;
     private String username;
     private String password;
     private String name;
     private String phone;
     private String email;
     private String state;
     private Set roles = new HashSet(0);
     private Set orderings = new HashSet(0);


    // Constructors

    /** default constructor */
    public User() {
    }

	/** minimal constructor */
    public User(String username, String password, String state) {
        this.username = username;
        this.password = password;
        this.state = state;
    }
    
    /** full constructor */
    public User(String username, String password, String name, String phone, String email, String state, Set roles, Set orderings) {
        this.username = username;
        this.password = password;
        this.name = name;
        this.phone = phone;
        this.email = email;
        this.state = state;
        this.roles = roles;
        this.orderings = orderings;
    }

   
    // Property accessors

    public Integer getUid() {
        return this.uid;
    }
    
    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return this.username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return this.phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return this.email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }

    public String getState() {
        return this.state;
    }
    
    public void setState(String state) {
        this.state = state;
    }

    public Set getRoles() {
        return this.roles;
    }
    
    public void setRoles(Set roles) {
        this.roles = roles;
    }

    public Set getOrderings() {
        return this.orderings;
    }
    
    public void setOrderings(Set orderings) {
        this.orderings = orderings;
    }

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> authortites = new ArrayList<GrantedAuthority>();
		Iterator<Role> it = roles.iterator();
		while(it.hasNext()){
			Role role = it.next();
			GrantedAuthority authority = new GrantedAuthorityImpl(role.getRoleDes());
			authortites.add(authority);
		}
		return authortites;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}